package com.example.hanchen.yongkanggy.utils;

import android.app.Activity;
import android.app.Dialog;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class DialogUtils {
    public static Dialog initDialog(Activity mContext, View view, int themeId, boolean cancelable, int gravity){
        Dialog dialog = new Dialog(mContext,themeId);
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(cancelable);
        WindowManager m = mContext.getWindowManager();
        Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值
        p.width = d.getWidth(); //宽度设置为屏幕
        dialog.getWindow().setAttributes(p); //设置生效
        dialog.getWindow().setGravity(gravity);
        return dialog;
    }
}
